<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">

	<div class="container-div ui-layout-center">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="user-form">
					<input type="hidden" name="userType" id="userType" value="01">
					<div class="select-list">
						<ul>
							<li>
								登录名称：<input type="text" name="loginName"/>
							</li>
							<li>
								手机号码：<input type="text" name="phonenumber"/>
							</li>
							<li>
								用户状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li class="select-time">
								<label>创建时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>


	        <div class="col-sm-12 select-table table-striped">
				<ul class="nav nav-tabs">
					<li class="active" onclick="queryUserList('01')"><a href="#normal" data-toggle="tab">普通用户</a></li>
					<li onclick="queryUserList('02')"><a href="#toolbar" data-toggle="tab">商家</a></li>
				</ul>
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:user:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
		var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
		var datas = [[${@dict.getType('sys_normal_disable')}]];
		var datas2 = [[${@dict.getType('sys_yes_no')}]];
		var prefix = ctx + "system/user";

		$(function() {
			queryUserList('01');
		});

		function queryUserList(userType) {
		    $("#userType").val(userType);
            $("#bootstrap-table").bootstrapTable('destroy');
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
                detailUrl: prefix+ "/detail/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "用户",
                queryParams:{userType:userType},//默认查询普通用户
                search: false,           // 是否显示搜索框功能
                showSearch: false,   // 是否显示检索信息
                showRefresh: false, // 是否显示刷新按钮
                showColumns: false, // 是否显示隐藏某列下拉框
                showToggle: false,   // 是否显示详细视图和列表视图的切换按钮
                showExport: false,

		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'userId',
		            title: '用户ID',
					visible:false
		        },
		        {
		            field: 'loginName',
		            title: '登录名称',
		            sortable: true
		        },
		        {
		            field: 'userName',
		            title: userType=='01'?'用户名称':'店铺名称'
		        },
				// {
				// 	field: 'isvip',
				// 	title: '会员',
				// 	formatter: function(value, row, index) {
				// 		return $.table.selectDictLabel(datas2, value);
				// 	},
				// 	visible:userType=='01'
				// },
		        {
		            field: 'email',
		            title: '邮箱',
		            visible: false
		        },
		        {
		            field: 'phonenumber',
		            title: '手机'
		        },
		        {
		            field: 'status',
		            title: '状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(datas, value);
		            }
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
                        actions.push('<a class="btn btn-link btn-sm " href="javascript:void(0)" onclick="$.operate.detail(\'' + row.userId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                        actions.push('<a class="btn btn-link btn-sm ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.userId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-link btn-sm ' + resetPwdFlag + '" href="javascript:void(0)" onclick="resetPwd(\'' + row.userId + '\')"><i class="fa fa-rotate-right"></i>重置</a> ');
                        actions.push('<a class="btn btn-link btn-sm ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.userId + '\')"><i class="fa fa-trash"></i>删除</a> ');
                        // if(row.userType == '01'){
						// 	if(row.isvip == 'N'){
                        //         actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="setIsvip(\'' + row.userId + '\',\'Y\')"><i class="fa fa-diamond"></i>开通会员</a> ');
                        //     }else{
                        //         actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="setIsvip(\'' + row.userId + '\',\'N\')"><i class="fa fa-diamond"></i>取消会员</a> ');
                        //     }
						// }

		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		}

		/*用户管理-重置密码*/
		function resetPwd(userId) {
		    var url = prefix + '/resetPwd/' + userId;
		    $.modal.open("重置密码", url, '800', '300');
		}

        function setIsvip(userId,isvip) {
			var json = {'N':'取消会员','Y':'开通会员'};
			$.modal.confirm("确定"+json[isvip]+"吗？",function () {
				$.operate.submit(prefix+"/edit","post","json",{userId:userId,isvip:isvip});
            })
        }
	</script>
</body>
</html>